//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package messages;

import common.ActionCode;
import common.ByteStream;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.zip.InflaterInputStream;

public class LoginFailed extends Base {
	public static final int MsgType = 20103;
	public int ErrorCode;
	public String ResourceFingerprintData;
	public String RedirectDomain;
	public String ContentURL;
	public String UpdateURL;
	public String Reason;
	public Integer MaintenanceTimeLeft;
	public String s1;
	public String s2;
	public byte b1;

	public LoginFailed() {
		super(20103);
	}

	public void encode(ByteStream stream) {
	}

	public void decode(ByteStream stream) {
		this.ErrorCode = stream.readInt();
		this.ResourceFingerprintData = stream.readString();
		this.RedirectDomain = stream.readString();
		ActionCode error = ActionCode.get(this.ErrorCode);
		if (!stream.isAtEnd() && stream.getLength() >= 4 && error == ActionCode.SERVER_MAINTENANCE) {
			this.ContentURL = stream.readString();
			this.MaintenanceTimeLeft = Integer.valueOf(stream.readInt());
		}

		if (error == ActionCode.OUT_OF_SYNC && this.ResourceFingerprintData.length() <= 0) {
			this.s1 = stream.readString();
			this.b1 = stream.readByte();
			int compressedLen = stream.readInt();
			stream.skip(8);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			if (compressedLen > 0) {
				compressedLen -= 4;
				byte[] compressedData = stream.readBytes(compressedLen);
				InflaterInputStream in = new InflaterInputStream(new ByteArrayInputStream(compressedData, 0, compressedLen));
				byte[] buffer = new byte[8192];

				try {
					int len;
					while ((len = in.read(buffer)) > 0) {
						baos.write(buffer, 0, len);
					}

					baos.flush();
				} catch (IOException var11) {
					var11.printStackTrace();
				}
			}

			if (baos.size() > 0) {
				try {
					this.ResourceFingerprintData = new String(baos.toByteArray(), "UTF-8");
				} catch (UnsupportedEncodingException var10) {
					;
				}
			}

			this.s2 = stream.readString();
		}

		this.isDecoded = true;
	}

	public String toString() {
		if (!this.isDecoded) {
			return super.toString();
		} else {
			String val = new String();
			val = val + String.format("     Error Code: %d (0x%08x)\n", new Object[]{Integer.valueOf(this.ErrorCode), Integer.valueOf(this.ErrorCode)});
			if (this.RedirectDomain != null) {
				val = val + String.format("     Redirect Domen: %s\n", new Object[]{this.RedirectDomain});
			}

			if (this.ContentURL != null) {
				val = val + String.format("     Content URL: %s\n", new Object[]{this.ContentURL});
			}

			if (this.UpdateURL != null) {
				val = val + String.format("     Update URL: %s\n", new Object[]{this.UpdateURL});
			}

			if (this.Reason != null) {
				val = val + String.format("     Reason: %s\n", new Object[]{this.Reason});
			}

			if (this.MaintenanceTimeLeft != null) {
				val = val + String.format("     Time Left: %d\n", new Object[]{this.MaintenanceTimeLeft});
			}

			return val;
		}
	}
}
